package com.xxx.modules.controller;;
import com.xxx.modules.service.RecordService;
import com.xxx.modules.entity.Record;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;

import com.xxx.modules.utils.Result;
import com.xxx.modules.utils.ResultUtil;



/**
 * record
 *
 * @author 北易航
 * @since 1.0.0 2022-12-28
 */
@RestController
@RequestMapping("/common/record")
@Api(tags="record")
public class RecordController {
    @Autowired
    private RecordService recordService;

    /**
     *  获取所有到访信息
     * @param pageNum
     * @param pageSize
     * @param record
     * @return
     */

    @GetMapping("/getRecordInfo")
    @ApiOperation("获取所有到访信息")
    public Result getRecordInfo(Record record, @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                @RequestParam(value="pageSize",defaultValue = "10") Integer pageSize){
        PageInfo<Record> data = recordService.selectRecordInfo(record,pageNum,pageSize);
        return ResultUtil.success(1,"成功",data);
    }

    /**
     * 保存到访信息
     * @param record
     * @return
     */
    @PostMapping("/saveRecordInfo")
    @ApiOperation("保存到访信息")
    public Result saveRecordInfo(@RequestBody Record record){
        recordService.saveRecordInfo(record);
        return ResultUtil.success(1,"成功",null);
    }


    /**
     * 更新到访信息
     * @param record
     * @return
     */

    @PutMapping("/updateRecordInfo")
    @ApiOperation("更新到访信息")
    public Result updateRecordInfo(@RequestBody Record record){
        recordService.updateRecordInfo(record);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id删除到访信息
     * @param id
     * @return
     */
    @DeleteMapping("/delRecordInfo")
    @ApiOperation("根据id删除到访信息")
    public Result delRecordInfo(Integer id){
        recordService.delRecordInfo(id);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id集合批量删除到访信息
     * @param idList
     * @return
     */
    @DeleteMapping("/delBatchRecordInfo")
    @ApiOperation("根据id集合批量删除到访信息")
    public Result delBatchRecordInfo(String idList){
        recordService.delBatchRecordInfo(idList);
        return ResultUtil.success(1,"成功",null);
    }

}